﻿package kit4j.util.concurrent;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.ThreadFactory;

/**
 * 具有指定的线程异常捕获器的线程构建工厂类型。
 * 
 * @author MiniKnife
 * 
 */
public class HandlerThreadFactory implements ThreadFactory {

	/**
	 * 线程异常捕获器。
	 */
	private UncaughtExceptionHandler handler;

	/**
	 * 创建一个线程构建工厂。
	 * @param handler 线程异常捕获器
	 */
	public HandlerThreadFactory(UncaughtExceptionHandler handler) {
		this.handler = handler;
	}

	/**
	 * @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
	 */
	@Override
	public Thread newThread(Runnable r) {
		Thread t = new Thread(r);

		t.setUncaughtExceptionHandler(handler);

		return t;
	}

}
